Fix xentrace to initialise the trace buffers if they are not set up.
authorkaf24@firebug.cl.cam.ac.uk <kaf24@firebug.cl.cam.ac.uk>
Fri, 12 May 2006 14:19:37 +0000 (15:19 +0100)
committerkaf24@firebug.cl.cam.ac.uk <kaf24@firebug.cl.cam.ac.uk>
Fri, 12 May 2006 14:19:37 +0000 (15:19 +0100)
Signed-off-by: Atsushi SAKAI <sakaia@jp.fujitsu.com>
tools/xentrace/xentrace.c

index e001704d2cd04475c1fb2f5cb29ae27d4d1cb332..b3a6b47a524c9b15f3d350bc5f584871c9fd547e 100644 (file)
@@ -28,6 +28,8 @@
 
 #include <xenctrl.h>
 
+#include "xc_private.h"
+
 #define PERROR(_m, _a...)                                       \
 do {                                                            \
     int __saved_errno = errno;                                  \
@@ -46,7 +48,7 @@ extern FILE *stderr;
 /* sleep for this long (milliseconds) between checking the trace buffers */
 #define POLL_SLEEP_MILLIS 100
 
-
+#define DEFAULT_TBUF_SIZE 20
 /***** The code **************************************************************/
 
 typedef struct settings_st {
@@ -101,6 +103,26 @@ void write_rec(unsigned int cpu, struct t_rec *rec, FILE *out)
     }
 }
 
+void enable_tracing_or_die(int xc_handle) 
+{
+  int enable = 1;
+  int tbsize = DEFAULT_TBUF_SIZE;
+  
+  if (xc_tbuf_enable(xc_handle, enable) != 0) {
+    if (xc_tbuf_set_size(xc_handle, tbsize) != 0) {
+      perror("set_size Hypercall failure");
+      exit(1);
+    }
+    printf("Set default trace buffer allocation (%d pages)\n", tbsize);
+    if (xc_tbuf_enable(xc_handle, enable) != 0) {
+      perror("Could not enable trace buffers\n");
+      exit(1);
+    }
+  }
+  else
+    printf("Tracing enabled\n");
+}
+
 /**
  * get_tbufs - get pointer to and size of the trace buffers
  * @mfn:  location to store mfn of the trace buffers to
@@ -111,22 +133,37 @@ void write_rec(unsigned int cpu, struct t_rec *rec, FILE *out)
  */
 void get_tbufs(unsigned long *mfn, unsigned long *size)
 {
-    uint32_t size32;
+    int ret;
+    dom0_op_t op;                        /* dom0 op we'll build             */
     int xc_handle = xc_interface_open(); /* for accessing control interface */
+    unsigned int tbsize;
 
-    if (xc_tbuf_get_size(xc_handle, &size32) != 0)
-        goto fail;
-    *size = size32;
+    enable_tracing_or_die(xc_handle);
 
-    if (xc_tbuf_get_mfn(xc_handle, mfn) != 0)
-        goto fail;
+    if (xc_tbuf_get_size(xc_handle, &tbsize) != 0) {
+      perror("Failure to get tbuf info from Xen. Guess size is 0?");
+      exit(1);
+    }
+    else
+      printf("Current tbuf size: 0x%x\n", tbsize);
+    
+
+    op.cmd = DOM0_TBUFCONTROL;
+    op.interface_version = DOM0_INTERFACE_VERSION;
+    op.u.tbufcontrol.op  = DOM0_TBUF_GET_INFO;
+
+    ret = do_dom0_op(xc_handle, &op);
 
     xc_interface_close(xc_handle);
-    return;
 
-fail:
-    PERROR("Failure to get trace buffer pointer from Xen");
-    exit(EXIT_FAILURE);
+    if ( ret != 0 )
+    {
+        PERROR("Failure to get trace buffer pointer from Xen");
+        exit(EXIT_FAILURE);
+    }
+
+    *mfn  = op.u.tbufcontrol.buffer_mfn;
+    *size = op.u.tbufcontrol.size;
 }
 
 /**